package 简单洗牌;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class CardGame {
    public static final String[] suits = {"♥","♣","♦","♠"};

    /*生成一副扑克牌
    * 生成52张 不包括大小王*/
    public List<Card> buyCard(){
        List<Card> cardList = new ArrayList<>();
        for(int i=0;i<4;i++)
        {
            for(int j =1;j<=13;j++){
                String suit =suits[i];
                Card card = new Card(suit,j);
                cardList.add(card);
            }
        }
        return cardList;
    }
    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() - 1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    private static void swap(List<Card> cardList,int i,int j){
        Card tmp=cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

    /*发牌  三个人轮流拿五张牌
     1.每个人拿到牌要放到哪里
     2.轮流抓 一人抓一张轮流抓五次*/
    public List<List<Card>> getCard(List<Card> cardList){
        List<Card> player1 = new ArrayList<>();
        List<Card> player2 = new ArrayList<>();
        List<Card> player3 = new ArrayList<>();

        List<List<Card>> player = new ArrayList<>();//用来放player
        player.add(player1);
        player.add(player2);
        player.add(player3);

        for(int i = 0;i<5;i++){
            for(int j =0;j<3;j++){//有三个人  拿牌是拿最上面拿一张也就是当前下标最小的那一张(0下标)
                Card card = cardList.remove(0);
                //怎么放到对应人手里
                player.get(j).add(card);
            }
        }

        return player;
    }
}
